package com.example.supplierfinancin.controller;

import com.example.util.ContractTools;
import com.google.gson.JsonObject;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple2;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("signup")
public class SignUpController {
    @PostMapping("register_bank")
    public String register_bank(String privatekey,String company,String uscc){
        /*
        return:
            {
                status:true
            }
         */
        Boolean temp= ContractTools.register_bank(privatekey,company,uscc);
        JsonObject ret=new JsonObject();
        ret.addProperty("status",temp);
        return ret.toString();
    }
    @PostMapping("register_company")
    public String register_company(String privatekey,String company,String uscc){
        /*
        return:
            {
                status:true
            }
         */

        Boolean temp= ContractTools.register_company(privatekey,company,uscc);

        JsonObject ret=new JsonObject();
        ret.addProperty("status",temp);
        return ret.toString();

    }
    @PostMapping("get_keypair")
    public String get_keypair(){
        /*
            {
                publickey:1564...
                privatekey:1435...
            }
         */
        Tuple2<String, String> temp=ContractTools.generate_key_pair();
        JsonObject ret=new JsonObject();
        ret.addProperty("publickey",temp.getValue1());
        ret.addProperty("privatekey",temp.getValue2());
        return ret.toString();
    }
}
